import { View, Text, Button } from "@tarojs/components";
import Taro, {
  useLoad,
  useDidShow,
  useDidHide,
  useUnload,
  useReady,
  useReachBottom,
  usePullDownRefresh,
} from "@tarojs/taro";
import "./index.less";
import { useState, useEffect } from "react";

import Child from "./components/Child";

export default function Index() {
  const [count, setCount] = useState(1);

  useLoad(() => {
    console.log("Page loaded.");
  });
  useDidShow(() => {
    console.log("Page showed.");
  });

  usePullDownRefresh(() => {
    console.log("Page pull down refresh.");
  });

  useEffect(() => {
    console.log("Page mounted.");
  }, []);

  const add = () => {
    setCount((v) => v + 1);
  };

  const fn = () => {
    Taro.switchTab({
      url: "/pages/about/index",
    });
  };

  return (
    <View className="index">
      <Text>Hello world!</Text>
      <View>{count}</View>
      <Button onClick={add}>count++</Button>
      <Child />
      <Button onClick={fn}>跳转到关于页</Button>
    </View>
  );
}
